FBDEditor.model.prototype.javascriptCodeCreator = function ( moduleId, x ) {
/*
    javascriptCodeCreator for FBDEditor 1.0
    Copyright (C) 2008-2009 Yuriy Butenko y.v.butenko@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
// x: { "v":[..], "f":[..], "i":[..], "o":[..], "txt":[..] };
	var res = 'function ' + moduleId + ' () {\n';
	var regExpIdTp = /^\s*([^\s]+)\s*(\:\s*([^\s]*)\s*)?$/;
	res += '/* FB */\n';
	for ( var i in x.f ) {
		var cls = x.f[i][1];
		var r = regExpIdTp.exec( x.f[i][0] );
		res += '\tvar ' + r[1] + ' = new ' + cls + '();\n';
	};
	for ( var i in x.v ) {
		var r = regExpIdTp.exec( x.v[i] );
		res += '\tvar ' + r[1] + ';\n';
	};
	res += '\tthis.init = function () {\n';
	for ( var i in x.f ) {
		var r = regExpIdTp.exec( x.f[i][0] );
		res += '\t\t' + r[1] + '.init();\n';
	};
	res += '\t};\n';
	res += '\tthis.eval = function () {\n';
	var c = x.txt;
	var isThis = function ( id, a ) {
		for ( var i = 0, l = a.length; i < l; i++ ) {
			var r = regExpIdTp.exec( a[i] );
			if ( r[1] == id ) return true;
		};
		return false;
	}
	for ( var i in c ) {
		var dstId = regExpIdTp.exec( c[i][1] );
		if ( !c[i][2] ) dstId = ( isThis(dstId[1],x.i) || isThis(dstId[1],x.o) ? "this." : "" ) + dstId[1];
		else dstId = dstId[1];
		var dstFld = c[i][2];
		switch ( c[i][0] ) {
			case 'cset':
				res += '\t\t' + dstId + ( dstFld ? "." + dstFld : "" ) + ' = ' + c[i][3] + ';\n';
				break;
			case 'set':
				var srcId = regExpIdTp.exec( c[i][3] );
				if ( !c[i][4] ) srcId = ( isThis(srcId[1],x.i) || isThis(srcId[1],x.o) ? "this." : "" ) + srcId[1];
				else srcId = srcId[1];
				var srcFld = c[i][4];
				res += '\t\t' + dstId + ( dstFld ? "." + dstFld : "" ) + ' = '
					+ srcId + ( srcFld ? "." + srcFld : "" ) + ';\n';
				break;
			case 'call':
				res += '\t\t' + dstId + '.eval();\n';
				break;
		};
	};
	res += '\t};\n';
	res += '};\n';
	res += moduleId + '.prototype = {\n';
	res += '/* Inputs */\n';
	for ( var i in x.i ) {
		var r = regExpIdTp.exec( x.i[i] );
		res += '\t"' + r[1] + '":null,\n';
	};
	res += '/* Outputs */\n';
	for ( var i in x.o ) {
		var r = regExpIdTp.exec( x.o[i] );
		res += '\t"' + r[1] + '":null,\n';
	};
	res	+= '\t"init":function () {},\n\t"eval":function(){}\n}\n';
	return res;
}
FBDEditor.model.prototype.javascriptCodeCreator.fileExt = ".js";
